package com.jinmdz.fmis.api.api.controller;

import com.jinmdz.fmis.api.api.model.common.DataCodeData;
import com.jinmdz.fmis.api.api.model.common.IdData;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.api.model.cremation.AppointmentTimeSegmentData;
import com.jinmdz.fmis.api.api.model.cremation.CremationAllData;
import com.jinmdz.fmis.api.api.model.cremation.CremationAllLoadData;
import com.jinmdz.fmis.api.api.model.cremation.CremationData;
import com.jinmdz.fmis.api.api.service.CremationService;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.model.cremation.AppointmentTimeSegmentCountItem;
import com.jinmdz.fmis.dao.model.cremation.CremationFurnaceViewItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;


/**
 * 火化任务信息相关接口
 *
 * @author LiCongLu
 * @date 2020-01-20 13:01
 */
@Api(description = "火化任务信息相关接口")
@RestController()
@RequestMapping("/api/cremation")
public class CremationController extends BaseController {

    @Resource
    private CremationService cremationService;

    /**
     * 根据cremation表中id加载火化任务信息
     *
     * @param data 火化主键
     * @return
     * @author LiCongLu
     * @date 2020-02-15 19:12
     */
    @ApiOperation(value = "根据cremation表中id加载火化任务信息", notes = "根据ID加载火化信息")
    @PostMapping("/load-cremation-with-id")
    public BaseResult<CremationData> loadCremationWithId(@RequestBody IdData data) {
        return resultHandler(data, userItem -> cremationService.loadCremationWithId(data));
    }

    /**
     * 加载火化预约时间段
     *
     * @param data 火化预约日期
     * @return
     * @author LiCongLu
     * @date 2020-03-08 15:24
     */
    @ApiOperation(value = "加载火化预约时间段", notes = "根据火化炉类型与火化预约日期加载火化时间段信息")
    @PostMapping("/load-appointment-time-segment-with-date")
    public BaseResult<ArrayList<AppointmentTimeSegmentCountItem>> loadAppointmentTimeSegmentWithDate(@RequestBody AppointmentTimeSegmentData data) {
        return resultHandler(data, userItem -> cremationService.loadAppointmentTimeSegmentWithDate(data));
    }

    /**
     * 保存火化信息到cremation表中
     *
     * @param data 火化请求数据
     * @return
     * @author LiCongLu
     * @date 2020-02-15 19:12
     */
    @ApiOperation(value = "保存火化信息到cremation表中", notes = "保存火化任务信息到cremation表中")
    @PostMapping("/saveCremation")
    public BaseResult<CremationData> saveCremation(@RequestBody CremationData data) {
        return resultHandler(data, userItem -> cremationService.saveCremation(userItem, data));
    }

    /**
     * 从cremation表中删除指定id的火化任务信息
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-02-15 19:12
     */
    @ApiOperation(value = "从cremation表中删除指定id的火化任务信息", notes = "从cremation表中删除指定id的火化任务信息")
    @PostMapping("/delete-cremation-with-id")
    public BaseResult deleteCremationWithId(@RequestBody IdVersionData data) {
        return resultHandler(data, userItem -> cremationService.deleteCremationWithId(userItem, data));
    }

    /**
     * 根据火化炉类型加载火化炉信息
     *
     * @param data 火化炉类型值
     * @return
     * @author LiCongLu
     * @date 2020-02-15 19:12
     */
    @ApiOperation(value = "根据火化炉类型加载火化炉信息", notes = "根据火化炉类型[火化炉类型字典编码：furnace_type]加载相应类型的火化炉信息")
    @PostMapping("/load-cremation-furnace-with-type")
    public BaseResult<ArrayList<CremationFurnaceViewItem>> loadCremationFurnaceWithType(@RequestBody DataCodeData data) {
        return resultHandler(data, userItem -> cremationService.loadCremationFurnaceWithType(data));
    }

    /**
     * 火化服务洽谈，界面权限验证及基础数据加载
     *
     * @param data 加载全部数据
     * @return
     * @author LiCongLu
     * @date 2020-01-20 13:09
     */
    @ApiOperation(value = "火化服务洽谈，界面权限验证及基础数据加载", notes = "针对页面定制接口，打开火化服务洽谈登记界面时使用本方法一次性加载所有界面初始化需要的数据\n" +
            "cremationId:火化记录ID\n" +
            "dictTypeCodes：火化相关字典信息【火化炉类型：furnace_type、骨灰处理方式：ashes_treatment、骨灰去向：ashes_whereabouts】等\n" +
            "serviceItemTypeCode:加载火化用物品服务信息【参数：use_in_cremation】")
    @PostMapping("/load-cremation-all")
    public BaseResult<CremationAllLoadData> loadCremationAll(@RequestBody CremationAllData data) {
        return resultHandler(data, userItem -> cremationService.loadCremationAll(data));
    }
}
